﻿/*
	Date:			05/25/2012
	Author:         Fabien Olousouzian
	License:      	Microsoft Public License (Ms-PL)
	Product:        XNA Shader Composer - Project
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using System.Diagnostics;

namespace Shader_Composer
{
    /// <summary>
    /// Singleton Design Pattern
    /// </summary>
    public sealed class DisplayInfoDebug
    {
        #region Singleton

        private static readonly Lazy<DisplayInfoDebug> lazy =
            new Lazy<DisplayInfoDebug>(() => new DisplayInfoDebug());

        public static DisplayInfoDebug Instance { get { return lazy.Value; } }

        #endregion

        #region Attributes

        private string _buffer;
        private Vector2 _position;
        private Color _color;

        private bool _status;
        private SpriteFont _font;

        #endregion

        #region Methods

        /// <summary>
        /// Ctor
        /// </summary>
        private DisplayInfoDebug()
        {
            _status = true;
            _buffer = "";
            _position = new Vector2(0,0);
            _color = Color.Yellow;
        }

        /// <summary>
        /// Load the font
        /// </summary>
        /// <param name="content"></param>
        /// <param name="nameFont"></param>
        public void Load(ContentManager content, string nameFont)
        {
            _font = content.Load<SpriteFont>(nameFont);
        }

        /// <summary>
        /// Update
        /// </summary>
        /// <param name="device"></param>
        public void Update(ref Device device)
        {
            if (device.buttonJustPressed(Microsoft.Xna.Framework.Input.Buttons.DPadUp) || (device.keyJustPressed(Microsoft.Xna.Framework.Input.Keys.H)))
                _status = !_status;
        }

        /// <summary>
        /// Draw the debug information
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void DrawInfoDebug(ref SpriteBatch spriteBatch)
        {
            if (_status && _buffer.Length > 0)
            {
                spriteBatch.Begin();
                spriteBatch.DrawString(_font, _buffer, _position, _color);
                spriteBatch.End();
              
            }
            _buffer = "";
        }

        #endregion

        #region Getter & Setter

        public bool Active
        {
            get { return _status; }
            set { _status = value; }
        }

        public string Buffer
        {
            get { return _buffer; }
            set { _buffer = value; }
        }

        public Vector2 Position
        {
            get { return _position; }
            set { _position = value; }
        }

        public Color Color
        {
            get { return _color; }
            set { _color = value; }
        }

        #endregion

    }
}
